class Book(val title: String, val author: String, val isbn: String) {
  var borrowed: Boolean = false

  def isborrowed: Boolean = borrowed

  def borrow(): Unit = {
    borrowed = true
  }

  def returnBook(): Unit = {
    borrowed = false
  }

  def apply(title: String, author: String, isbn: String): Book = {
    new Book(title, author, isbn)

  def unapply(book: Book): Option[(String, String, String)] = {
    Some(book.title, book.author, book.isbn)
}
  }

class Library(var books: List[Book] = Nil) {
  def addBook(book: Book): Unit = {
    books = book :: books
  }

  def borrowBook(isbn: String): Unit = {
    val index = findBookIndexByIsbn(isbn)
    if (index >= 0) {
      val book = books(index)
      if (!book.borrowed) {
        book.borrow()
        println(s"这本书已经借出.")
      } else {
        println("没有这本书")
      }
    } else {
      println("这本书没有找到")
    }
  }

  def returnBook(isbn: String): Unit = {
    val index = findBookIndexByIsbn(isbn)
    if (index >= 0) {
      val book = books(index)
      if (book.borrowed) {
        book.returnBook()
        println(s"这本书已经归还")
      } else {
        println("这本书未从图书馆借出")
      }
    } else {
      println("这本书没有找到")
    }
  }
}
}